package leetcode.code2059;

import java.util.LinkedList;
import java.util.Queue;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int minimumOperations(int[] nums, int start, int goal) {
		boolean[] seen = new boolean[1001];
		Queue<int[]> queue = new LinkedList<>();
		int len = nums.length;
		seen[start] = true;
		queue.add(new int[] { start, 0 });
		int[] xx = new int[3];
		while (!queue.isEmpty()) {
			int[] cur = queue.poll();
			int x = cur[0], dist = cur[1] + 1;
			for (int i = 0; i < len; i++) {
				int num = nums[i];
				xx[0] = x + num;
				xx[1] = x - num;
				xx[2] = x ^ num;
				for (int j = 0; j < 3; j++) {
					if (xx[j] == goal) {
						return dist;
					}
					if (xx[j] >= 0 && xx[j] <= 1000 && !seen[xx[j]]) {
						seen[xx[j]] = true;
						queue.add(new int[] { xx[j], dist });
					}
				}
			}
		}
		return -1;

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
